<template>
    <div class="order_manage">
        <Header></Header>
        <h1>这是我的发票页</h1>
<<<<<<< HEAD
        <el-container style="height: 1000px; border: 1px solid #eee">
            <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
                <el-menu :default-openeds="['1', '3']">
                    <el-submenu index="1">
                        <template slot="title"><i class="el-icon-menu"></i>我的订单</template>
                        <el-menu-item index="1-1" @click="goPage('/order_manage')"
                                      :class="{active: url_path === '/order_manage'}">订单管理
                        </el-menu-item>
                    </el-submenu>
                    <el-submenu index="2">
                        <template slot="title"><i class="el-icon-menu"></i>我的资产</template>
                        <el-menu-item index="2-1" @click="goPage('/money')"
                                      :class="{active: url_path === '/money'}">账户余额
                        </el-menu-item>
                        <el-menu-item index="2-2" @click="goPage('/score')"
                                      :class="{active: url_path === '/score'}">我的积分
                        </el-menu-item>
                    </el-submenu>
                    <el-submenu index="3">
                        <template slot="title"><i class="el-icon-setting"></i>个人中心</template>
                        <el-menu-item index="3-1" @click="goPage('/self_center')"
                                      :class="{active: url_path === '/self_center'}">用户信息
                        </el-menu-item>
                        <el-menu-item index="3-2" @click="goPage('/receipt')"
                                      :class="{active: url_path === '/receipt'}">我的发票
                        </el-menu-item>
                        <el-menu-item index="3-3" @click="goPage('/traffic')"
                                      :class="{active: url_path === '/traffic'}">我的违章
                        </el-menu-item>
                        <el-menu-item index="3-4" @click="goPage('/complain')"
                                      :class="{active: url_path === '/complain'}">在线投诉
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main width="1000px" style="background-color: rgb(246, 241, 239)">
                <el-button type="text" @click="diag = true">新增发票</el-button>
                <el-drawer
                        title="新增发票"
                        :visible.sync="diag"
                        direction="rtl"
                        custom-class="demo-drawer"
                        ref="drawer"
                >
                    <div class="demo-drawer__content">
                        <el-form :model="form">
                            <el-form-item label="增加发票" :label-width="formLabelWidth">
                                <el-select v-model="form.order" placeholder="请选择订单">
                                    <el-option v-for="order in order_list" :label="order.id"
                                               v-model="order.id"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="发票抬头" :label-width="formLabelWidth">
                                <el-input v-model="form.invoice" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="收件人姓名" :label-width="formLabelWidth">
                                <el-input v-model="form.address_name" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="手机号" :label-width="formLabelWidth">
                                <el-input v-model="form.mobile" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="邮编" :label-width="formLabelWidth">
                            <el-input v-model="form.zip" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="收件地址" :label-width="formLabelWidth">
                            <el-input v-model="form.addr" autocomplete="off"></el-input>
                            </el-form-item>
                        </el-form>
                        <div class="demo-drawer__footer">
                            <el-button @click="cancelForm">取 消</el-button>
                            <el-button type="primary" @click="add_receipt">确定
                            </el-button>
                        </div>
                    </div>
                </el-drawer>
                <br><br><br><br>
                <hr>
            </el-main>
        </el-container>
=======
        <Center></Center>
>>>>>>> c08a2c9afaf2d3b270a8ee3abf17b8f918215c8e
        <Footer></Footer>
    </div>
</template>

<script>
    import Header from "../components/Header";
    import Center from "../components/Center";
    import Footer from "../components/Footer";
<<<<<<< HEAD

    export default {
        name: "Receipt",
        components: {Footer, Center, Header},
        data() {
            return {
                url_path: sessionStorage.url_path || '/',
                diag: false,
                order_list: [],
                form: {
                    order: '',
                    invoice: '',
                    address_name: '',
                    mobile: '',
                    zip: '',
                    addr: '',
                },
                formLabelWidth: '90px',
                timer: null,
            }
        },
        methods: {
            goPage(url_path) {
                //已经是当前路由就没有必要重新跳转
                if (this.url_path !== url_path) {
                    this.$router.push(url_path);
                }
                sessionStorage.url_path = url_path
            },
            cancelForm() {
                this.loading = false;
                this.diag = false;
                clearTimeout(this.timer);
            },
            add_receipt() {
                this.$axios({
                    url: `${this.$settings.base_url}/user/receipt`,
                    method: 'post',
                    data: {
                        order: this.form.order,
                        invoice: this.form.invoice,
                        address_name: this.form.address_name,
                        mobile: this.form.mobile,
                        zip: this.form.zip,
                        addr: this.form.addr,
                    }
                }).then(response => {
                    this.$message({
                        message: response.data
                    });
                }).catch( error =>{
                    this.$message({
                        message: error.response.data
                    })
                })
            },
        },
        created() {
            this.$axios.get(`${this.$settings.base_url}/order/search?user=${this.$cookies.get('user_id')}`, {}).then(response => {
                this.order_list = response.data;
                console.log(this.order_list)
            }).catch(() => {
                this.$message({
                    message: '获取订单信息有误，请联系客服工作人员'
                })
            });
            sessionStorage.url_path = this.$route.path;
            this.url_path = this.$route.path;
        }
=======
    export default {
        name: "Receipt",
        components: {Footer, Center, Header}
>>>>>>> c08a2c9afaf2d3b270a8ee3abf17b8f918215c8e
    }
</script>

<style scoped>
<<<<<<< HEAD
    .el-header {
        background-color: #B3C0D1;
        color: #333;
        line-height: 60px;
    }

    .el-aside {
        color: #333;
    }
=======

>>>>>>> c08a2c9afaf2d3b270a8ee3abf17b8f918215c8e
</style>